package org.example.controller;

import org.example.entity.WrongQuestionEntity;
import org.example.service.WrongQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wrongQuestions")
public class WrongQuestionController {

    @Autowired
    private WrongQuestionService wrongQuestionService;

    // 获取所有错题记录
    @GetMapping("/get")
    public List<WrongQuestionEntity> getAllWrongQuestions() {
        return wrongQuestionService.getAllWrongQuestions();
    }

    // 根据学生ID获取错题记录
    @GetMapping("/student/{studentId}")
    public List<WrongQuestionEntity> getWrongQuestionsByStudentId(@PathVariable int studentId) {
        return wrongQuestionService.getWrongQuestionsByStudentId(studentId);
    }

    // 获取单个错题记录
    @GetMapping("/{wrongId}")
    public WrongQuestionEntity getWrongQuestionById(@PathVariable int wrongId) {
        return wrongQuestionService.getWrongQuestionById(wrongId);
    }

    // 添加错题记录
    @PostMapping("/add")
    public String saveWrongQuestion(@RequestBody WrongQuestionEntity wrongQuestionEntity) {
        wrongQuestionService.saveWrongQuestion(wrongQuestionEntity);
        return "错题记录保存成功";
    }

    // 更新错题记录
    @PutMapping("/{wrongId}")
    public String updateWrongQuestion(@PathVariable int wrongId, @RequestBody WrongQuestionEntity wrongQuestionEntity) {
        wrongQuestionEntity.setWrongId(wrongId);
        wrongQuestionService.updateWrongQuestion(wrongQuestionEntity);
        return "错题记录更新成功";
    }

    // 删除错题记录
    @DeleteMapping("/{wrongId}")
    public String deleteWrongQuestion(@PathVariable int wrongId) {
        wrongQuestionService.deleteWrongQuestion(wrongId);
        return "错题记录删除成功";
    }
}
